package com.welsmann.app.start.spider.dao;

import java.util.List;

import com.welsmann.app.start.spider.dao.helper.QueryHelper;
import com.welsmann.app.start.spider.entity.Newspider;

/**
 * 新闻爬虫操作类
 * 
 * @author Welsmann
 * 
 */
public class NewspiderDAO {

	/**
	 * 获取所有
	 * 
	 * @return
	 */
	public static List<Newspider> findAll() {
		return QueryHelper.list(Newspider.class, "select * from newspider",
				null);
	}

	/**
	 * 根据主键获取
	 * 
	 * @param id
	 * @return
	 */
	public static Newspider find(String id) {
		return QueryHelper.single(Newspider.class,
				"select * from newspider where id = ?", id);
	}

	/**
	 * 新增
	 * 
	 * @param nt
	 * @return
	 */
	public static int insert(Newspider nt) {
		return QueryHelper.update("insert into newspider values(?,?,?,?,?)",
				nt.getId(), nt.getSource(), nt.getRule(), nt.getType(),
				nt.getLimit());
	}

	/**
	 * 更新
	 * 
	 * @param nt
	 * @return
	 */
	public static int update(Newspider nt) {
		return QueryHelper
				.update("update newspider set source = ?, column = ?, article = ? , limit = ? where id = ?",
						nt.getSource(), nt.getRule(), nt.getType(),
						nt.getLimit(), nt.getId());
	}

	/**
	 * 对象删除
	 * 
	 * @param nt
	 * @return
	 */
	public static int delete(Newspider nt) {
		return QueryHelper.update("delete from newspider where id  = ? ",
				nt.getId());
	}

	/**
	 * 对象删除
	 * 
	 * @param id
	 * @return
	 */
	public static int delete(String id) {
		return QueryHelper.update("delete from newspider where id  = ? ", id);
	}
}
